Convert geological units from Leapfrog (*.msh) to VTK using Python and GemGIS - Tutorial
/This tutorial shows the complete procedure to convert a geological unit as a Leapfrog mesh (*.msh) to the VTK (Visualization Toolkit) format using Python and GemGIS. Follow these steps to seamlessly transfer your geological data for advanced visualization, analysis and comparison with other model results.
Tutorial
#import required packages
import gemgis as gg
import numpy as np
import pyvista as pv
import os
#define mesh and vtk dir
meshDir = '../Mesh'
vtkDir = '../Vtk'
#open all meshs and filter
meshList = os.listdir(meshDir)
meshList = [x for x in meshList if x.endswith('msh')]
meshList
['GM_Breccia.msh',
'GM_Dyke.msh',
'GM_Granodiorite.msh',
'GM_Marble.msh',
'GM_Sandstone.msh']
#define a funtion to convert
def convertMshtoVtk(file):
srcPath = os.path.join(meshDir,file)
outPath = os.path.join(vtkDir,file[:-3]+'vtk')
tempDict = gg.raster.read_msh(srcPath)
tempMesh = gg.visualization.create_polydata_from_msh(tempDict)
tempMesh.save(outPath)
return tempMesh
#convert all vtks
GM_Breccia = convertMshtoVtk('GM_Breccia.msh')
GM_Dyke = convertMshtoVtk('GM_Dyke.msh')
GM_Granodiorite = convertMshtoVtk('GM_Granodiorite.msh')
GM_Marble = convertMshtoVtk('GM_Marble.msh')
GM_Sandstone = convertMshtoVtk('GM_Sandstone.msh')
#to prevent warnings of pyvista
import warnings
warnings.filterwarnings('ignore')
#plot geological units as vtks
p = pv.Plotter(notebook=True)
p.add_mesh(GM_Breccia, color='crimson')
p.add_mesh(GM_Dyke, color='teal')
p.add_mesh(GM_Granodiorite, color='gold')
p.add_mesh(GM_Marble, color='snow')
p.add_mesh(GM_Sandstone, color='slategrey')
#p.camera_position = [(0, 0, 5), (0, 0, 0), (0, 1, 0)]
p.show_grid(color='black')
p.set_background(color='white')
p.show()